package com.rimi.service.impl;

import com.rimi.bean.PreMed;
import com.rimi.bean.Prescription;
import com.rimi.commons.CommonResult;
import com.rimi.commons.ResultStatus;
import com.rimi.mapper.PrescriptionMapper;
import com.rimi.service.PrescriptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class PrescriptionServiceImpl implements PrescriptionService {

    @Autowired
    PrescriptionMapper prescriptionMapper;

    @Override
    public List<Prescription> findprescriptionByUserId(Integer userId) {
        return prescriptionMapper.findPrescriptionByUserId(userId);

    }

    @Override
    public CommonResult addPreMed(PreMed preMed) {

        int res = prescriptionMapper.addPreMed(preMed);
        return res == 1 ? CommonResult.onSuccess(null) : CommonResult.onFailed(ResultStatus.ADD_FAILED);
    }

    @Override
    @Transactional
    public CommonResult addPrescription(Prescription prescription) {
        int res = prescriptionMapper.addPrescription(prescription);
        return res == 1 ? CommonResult.onSuccess(null) : CommonResult.onFailed(ResultStatus.ADD_FAILED);
    }

    @Override
    public CommonResult deletePrescriptionByUser(String prescriptionId) {
        int res = prescriptionMapper.deletePrescriptionByUser(prescriptionId);
        return res == 1 ? CommonResult.onSuccess(null) : CommonResult.onFailed(ResultStatus.ADD_FAILED);
    }

    @Override
    public CommonResult setMedicalrecordsByUser(String appointmentTime, String petId) {
        int res = prescriptionMapper.setMedicalrecordsByUser(appointmentTime, petId);
        return res == 1 ? CommonResult.onSuccess(null) : CommonResult.onFailed(ResultStatus.UPDATE_FAILED);
    }

    @Override
    public CommonResult setPrescriptionByUser(String prescriptionDate, String petsId) {
        int res = prescriptionMapper.setPrescriptionByUser(prescriptionDate, petsId);
        return res == 1 ? CommonResult.onSuccess(null) : CommonResult.onFailed(ResultStatus.UPDATE_FAILED);
    }

}
